﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ListenMusic.Category_ServiceReference;
using System.ServiceModel;
using ListenMusic.Models.ViewModel;
namespace ListenMusic.Models.Reposistory.Public
{
    public class CategoryReposistory
    {
        CategoryServiceClient clientCategory;
        CountryReposistory _country;
        public CategoryReposistory()
        {
            clientCategory = new CategoryServiceClient();
         
        }
        public List<Category> getAllCategory()
        {
            try {
                Category[] allCategory = clientCategory.getAllCategory();
                return allCategory.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<Category> getCategory_byCountry(int countryid)
        {
            try
            {
                Category[] allCategory = clientCategory.getCategory_byCountry(countryid);
                return allCategory.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<CountryCategory> getCategory_byCountry()
        {
            _country = new CountryReposistory();
            try
            {
                var q = from c in _country.getAllCountry()
                        select new CountryCategory()
                        {
                            CountryID = c.CountryID,
                            CountryName = c.CountryName,
                            category = getCategory_byCountry(c.CountryID).ToList(),
                        };
                return q.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        
    }
}